package com.taotao.web;

import com.taotao.common.TaotaoResult;
import com.taotao.service.TbItemService;
import com.taotao.common.EasyUIResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/item")
public class TbItemController {

    @Autowired
    private TbItemService tbItemService;

    /**
     * 查詢商品
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping("/list")
    @ResponseBody
    public EasyUIResult getTbItemList(@RequestParam("page") int pageNum, @RequestParam("rows") int pageSize) {
        EasyUIResult easyUIResult = tbItemService.getTbItemList(pageNum, pageSize);
        return easyUIResult;
    }

    /**
     * 新增商品
     * @param cid
     * @param title
     * @param sellPoint
     * @param price
     * @param num
     * @param barcode
     * @param image
     * @param desc
     * @param itemParams
     * @return
     */
    @RequestMapping("/save")
    @ResponseBody
    public TaotaoResult addTbItem(long cid,String title,String sellPoint,long price,int num,String barcode,String image,String desc,String itemParams){
        TaotaoResult taotaoResult = tbItemService.addTbItem(cid,title,sellPoint,price,num,barcode,image,desc,itemParams);
        return taotaoResult;
    }

    /**
     * 修改商品
     * @param id
     * @param cid
     * @param title
     * @param sellPoint
     * @param price
     * @param num
     * @param barcode
     * @param image
     * @param desc
     * @param itemParams
     * @param itemParamId
     * @return
     */
    @RequestMapping("/update")
    @ResponseBody
    public TaotaoResult updateTbItem(long id,long cid,String title,String sellPoint,long price,int num,String barcode,String image,String desc,String itemParams,long itemParamId){
        TaotaoResult taotaoResult = tbItemService.updateTbItem(id,cid,title,sellPoint,price,num,barcode,image,desc,itemParams,itemParamId);
        return taotaoResult;
    }

    /**
     * 刪除商品
     * @param ids
     * @return
     */
    @RequestMapping("/delete")
    @ResponseBody
    public TaotaoResult deleteTbItem(@RequestParam("ids") long[] ids) {
        TaotaoResult taotaoResult = tbItemService.changeTbItemStatus(ids, (byte) 3);
        return taotaoResult;
    }

    /**
     * 下架商品
     * @param ids
     * @return
     */
    @RequestMapping("/instock")
    @ResponseBody
    public TaotaoResult instockTbItem(@RequestParam("ids") long[] ids) {
        TaotaoResult taotaoResult = tbItemService.changeTbItemStatus(ids, (byte) 2);

        return taotaoResult;
    }

    /**
     * 上架商品
     * @param ids
     * @return
     */
    @RequestMapping("/reshelf")
    @ResponseBody
    public TaotaoResult reshelfTbItem(@RequestParam("ids") long[] ids) {
        TaotaoResult taotaoResult = tbItemService.changeTbItemStatus(ids, (byte) 1);

        return taotaoResult;
    }

}
